<?php

if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );

class Controller_Global extends CI_Controller {

	public function __construct() {
		parent::__construct ();
		require(APPPATH.'helpers/protocal.php');
		$this->load->model ( 'Model_Global', 'Global' );
		
	}
	
	protected function get_global_data() {
		$result = null;
		$result->return_code = 0;
		$result->protocal = get_protocal( $_GET ['protocal'] );
		$userid = $_GET['userid'];
		
		$query = $this->Global->get_user_competition_data($userid );
		if ($query != null) {
			$result->competition = $query;
		}
		
		$query = $this->Global->get_cg_update_data($userid);
		if ($query != null) {
			$result->cg_period = $query->period;
			$result->cg_number_vote = $query->number_vote;
			$result->cg_number_weak = $query->number_weak;
			$result->cg_ranking = $query->ranking;
		}
		
		$query = $this->Global->get_pk_update_data($userid);
		if ($query != null) {
			$result->pk_period = $query->period;
			$result->pk_count = $query->pk_count;
			$result->pked_count = $query->pked_count;
			$result->pked_success = $query->pked_success;
			$result->pked_failed = $query->pked_failed;
			$result->pk_score = $query->score;
			$result->pk_ranking = $query->ranking;
		}
		
		$query = $this->Global->get_friend_update_data($userid);
		if ($query != null) {
			$result->fans_count = $query->fans_count;
		}
		
		$this->output->set_output ( json_encode ( $result ) );
	}
	
	public function index() {
		
		if (IS_MAINTAINING) {
			return ;
		}
		
		$protocal = get_protocal( $_GET['protocal'] );
		switch ($protocal) {
			case 1050 :
				$this->get_global_data ();
				break;
			default :
				break;
		}
	}
}
